<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>鼠标拖拽</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            background-color: black;
            position: fixed;
        }
    </style>
</head>

<body>
    <div></div>
</body>
<script>
    document.body.querySelector('div').onmouseover = function (e) {
        document.body.querySelector('div').style.top = e.pageY + 'px'
        document.body.querySelector('div').style.left = e.pageX + 'px'
    }
</script>

</html>